package com.cy.model;

import com.cy.BasicModel;
import com.cy.ext.plugin.tablebind.TableBind;

import java.util.Date;

@TableBind(tableName="site_map_device", pkName = "id")
public class SiteMapDevice extends BasicModel<SiteMapDevice> {
    public static final SiteMapDevice dao = new SiteMapDevice();
    public static final String SELECT_ALL = "`id`,`site_id`,`device_id`,`start_date`,`end_date`";

    /**
     * 设备是否可用
     */
    public boolean isEnabledDevice(Long siteId, Long deviceId){
        SiteMapDevice smd = findFirst("SELECT * FROM site_map_device WHERE site_id = ? AND device_id = ? AND start_date <= CURDATE() AND end_date >= CURDATE()", siteId, deviceId);
        return smd == null;
    }

    public SiteMapDevice setId(Long id){
        return this.set("id", id);
    }

    public Long getId(){
        return this.get("id");
    }
            
    public SiteMapDevice setSiteId(Long siteId){
        return this.set("site_id",siteId);
    }

    public Long getSiteId(){
        return this.get("site_id");
    }
        
    public SiteMapDevice setDeviceId(Long deviceId){
        return this.set("device_id",deviceId);
    }

    public Long getDeviceId(){
        return this.get("device_id");
    }
        
    public SiteMapDevice setStartDate(Date startDate){
        return this.set("start_date",startDate);
    }

    public Date getStartDate(){
        return this.getDate("start_date");
    }
        
    public SiteMapDevice setEndDate(Date endDate){
        return this.set("end_date",endDate);
    }

    public Date getEndDate(){
        return this.getDate("end_date");
    }
}